package com.paw.ruoyi.admin.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Rubble
 * @date 2022/2/25
 **/
@Configuration
public class WxConfig {

  @Autowired
  WxProperties wxProperties;

  @Bean
  public WxMaService wxMaService(){
    WxMaService wxMaService = new WxMaServiceImpl();
    wxMaService.setWxMaConfig(wxMaConfig());
    return wxMaService;
  }


  @Bean
  public WxMaConfig wxMaConfig(){
    WxMaDefaultConfigImpl wxMaService = new WxMaDefaultConfigImpl();

    wxMaService.setAppid(wxProperties.getAppid());
    wxMaService.setSecret(wxProperties.getSecret());
    return wxMaService;
  }


  @Bean
  public WxMpService wxMpService(){
    WxMpService wxMpService = new WxMpServiceImpl();
    wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
    return wxMpService;
  }


  @Bean
  public WxMpConfigStorage wxMpConfigStorage(){
    WxMpDefaultConfigImpl wxMpConfigStorage = new WxMpDefaultConfigImpl();
    wxMpConfigStorage.setAppId(wxProperties.getAppid());
    wxMpConfigStorage.setSecret(wxProperties.getSecret());
    return wxMpConfigStorage;
  }

}
